
/**
 *	function change password
 *
 */

$(document).ready(function() {

	//Change pass 
	$('#c-submit').click(function() {

	// Get information from form
	var old_pass = $('.old-pass').val();
	var new_pass = $('.new-pass').val();
	var confirm_pass = $('.c-new-pass').val();

	// If they are empty
	if(old_pass == "" || new_pass == "" || confirm_pass == "") {
		confirm("There are some fields is empty.");
		return false;
	}

	// Confirm two news pass
	if(new_pass != confirm_pass) {

		confirm("Two new password should be the same!");
		return false;
	}
		var id = $('.yourPic').attr('id');
		
		$.ajax({
			url: "Model/cupdate.php",
			type: "post",
			data: "action=changepass&id="+id+"&newpass="+new_pass+"&oldpass="+old_pass,
			success: function(result) {
				alert(result);
				$('#c-pass').hide(100);
			}
		});
	});

	// When user click finish button
		$('.edit-finish').click(function() {

			var id = $('.yourPic').attr('id');
			
			// Get information
			var des = $('.ta').val();
			var firstname = $('.firstname').val();
			var lastname = $('.lastname').val();
			var birthday = $('.birthday').val();
			var gender = $('.gender').val();
			var nickname = $('.nickname').val();
			var address = $('.address').val();
			var shelteradd = $('.shelteradd').val();
			var highschool = $('.highschool').val();
			var university = $('.university').val();
			var cellphone = $('.cellphone').val();

			var data = "action=updateinfo&id="+id+"&ta="+des+"&firstname="+firstname+"&lastname="+lastname+"&birthday="+birthday+"&gender="+gender+"&nickname="+nickname+"&address="+address+"&shelteradd="+shelteradd+"&highschool="+highschool+"&university="+university+"&cellphone="+cellphone;

			alert(data);

			// AJAX
			$.ajax({
				url: 'Model/cupdate.php',
				type: 'post',
				data: data,
				success: function(response) {
					alert(response);
				}
			});
		});
});